package org.alex.nettychat.netty.custom.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.group.ChannelGroup;
import org.alex.nettychat.netty.custom.config.Attributes;
import org.alex.nettychat.netty.custom.protocol.SendToGroupRequestPacket;
import org.alex.nettychat.netty.custom.protocol.SendToGroupResponsePacket;
import org.alex.nettychat.netty.custom.session.Session;
import org.alex.nettychat.netty.custom.utils.SessionUtil;


/**
 * 创建群里请求
 *
 * @author : alex
 */
public class SendToGroupResponseHandler extends SimpleChannelInboundHandler<SendToGroupResponsePacket> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, SendToGroupResponsePacket sendToGroupResponsePacket) throws Exception {
        Session session = ctx.attr(Attributes.SESSION).get();
        if (session.getUserId() == sendToGroupResponsePacket.getSendUserId()) {
            System.out.println("me:" + sendToGroupResponsePacket.getMsg());
        } else {
            System.out.println("收到群聊[" + sendToGroupResponsePacket.getGroupId() + "]中[" + sendToGroupResponsePacket.getSendUserName() + "]的消息：" + sendToGroupResponsePacket.getMsg());
        }
    }
}
